#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
int main()
{
	LL y, z; cin >> y >> z;
	LL ret = 1e12 + 10;
	for(LL k = 100000; k < 1000000; k++)
	{
		LL tmp = k * 1000000 + y;
		ret = min(ret, abs(tmp - z));
	}
	cout << ret << endl;
	return 0;
}
